package ExerciseOne;

public class ThreadSafe4Test {
	public static void main(String[] args) {
		Window4 w1 = new Window4();
		Window4 w2 = new Window4();
		w1.setName("线程一");
		w2.setName("线程二");
		w1.start();
		w2.start();
	}

}

class Window4 extends Thread
{
	private static int ticket = 100;
	@Override
	public void run() {
		while(true)
		{
			show();
		}
	}
	
	private static synchronized void show()
	{
		if(ticket>0)
		{
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName()+":"+ticket);
			ticket--;
		}
	}
}